package Main;
//TODO can be delete
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;

import DataObjects.Topic;

public class TopicsReader {
	
	
	private static Topic lineToTopic(String line){
		String[] splited=line.split(" ");
		String[] splited2 = splited[0].split(""+(char)9);
		Topic topic=new Topic(Integer.parseInt(splited2[0]));
		topic.addWord(splited2[2]);
		for(int i=1;i<splited.length;i++){
			topic.addWord(splited[i]);
		}
		System.out.println(topic.getName());
		return topic;
	}
	
	
	public static Vector<Topic> topicsReader(String fileName){
		Vector<Topic> ans=new Vector<Topic>();
		try {
			BufferedReader reader=new BufferedReader(new FileReader(new File(fileName)));
			
			String topicLine=reader.readLine();
			while (topicLine!=null){
				Topic topic=lineToTopic(topicLine);
				ans.add(topic.getId(),topic);
				
				topicLine=reader.readLine();
			}
			
			reader.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return ans;
	}
}
